import cv2
import  numpy as np
image=cv2.imread('book.png')
#定义原四边形和目标四边形的顶点坐标
src_pts=np.float32([[120,27],[352,37],[46,350],[315,370]])
dst_pts=np.float32([[50,50],[350,50],[50,350],[350,350]])
#获取透视变换矩阵
M=cv2.getPerspectiveTransform(src_pts,dst_pts)
#对图像进行透视变换
warped_image=cv2.warpPerspective(image,M,(400,400))
#显示原图像和透视变换后的图像
cv2.imshow('Input',image)
cv2.imshow('Perspective',warped_image)
cv2.waitKey()
cv2.destroyAllWindows()